package com.kingint.web.portal.serve.controller;


import com.kingint.mbg.group.Insert;
import com.kingint.mbg.group.Update;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.kingint.common.unitedresult.K;

import com.kingint.web.portal.serve.service.CycleCleanPlanService;
import com.kingint.mbg.ser.entity.SerCycleCleanPlan;


/**
 * @描述：周期卫生计划表控制类
 * @作者: wxh
 * @日期: 2021-01-11
 */
@RestController
@RequestMapping("/cycleCleanPlan")
@Api(value = "SerCycleCleanPlanController", description = "周期卫生计划表")
@CrossOrigin
public class CycleCleanPlanController {

    @Autowired
    public CycleCleanPlanService cycleCleanPlanService;


    @ApiOperation(value = "添加周期卫生计划表")
    @PostMapping("/create")
    public Object create(@Validated(Insert.class) @RequestBody SerCycleCleanPlan serCycleCleanPlan) {
        boolean b = cycleCleanPlanService.createPlan(serCycleCleanPlan);
        if (b) {
            return K.ok().data(b);
        } else {
            return K.error();
        }
    }


    @ApiOperation(value = "更新周期卫生计划表")
    @PutMapping("/update")
    public Object update(@Validated(Update.class) @RequestBody SerCycleCleanPlan serCycleCleanPlan) {
        Boolean bool = cycleCleanPlanService.updatePlan(serCycleCleanPlan);
        if (bool) {
            return K.ok().data(serCycleCleanPlan.getId());
        } else {
            return K.error();
        }
    }

    @ApiOperation(value = "根据周期卫生计划表名称分页获取周期卫生计划表列表")
    @GetMapping("/list")
    public Object getList(SerCycleCleanPlan serCycleCleanPlan,
                          @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                          @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize) {
        Page<SerCycleCleanPlan> page = new Page<>(pageNum, pageSize);

        IPage<SerCycleCleanPlan> info = cycleCleanPlanService.getpage(page);
//        IPage<SerCycleCleanPlan> info=serCycleCleanPlanService.page(page,null);
        return K.ok().data(info);
    }

    @ApiOperation(value = "根据编号查询周期卫生计划表信息")
    @GetMapping("/getCycleInfo")
    public Object getItem(@RequestParam("id") Integer id) {
        SerCycleCleanPlan serCycleCleanPlan = cycleCleanPlanService.getonebyid(id);
//        SerCycleCleanPlan serCycleCleanPlan=serCycleCleanPlanService.getById(id);
        return K.ok().data(serCycleCleanPlan);
    }
}